package cn.doourbest.learnspring.mapping;

import cn.doourbest.learnspring.service.LearnSpringService;
import cn.doourbest.learnspring.service.TwoService;
import cn.doourbest.learnspring.service.impl.ServiceBO;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.xml.ws.Action;
import java.io.IOException;

/**
 * @description:
 * @author: zhangsc
 * @create: 2019/10/25
 */
@RestController
public class ZscController {

    public ZscController(LearnSpringService learnSpringService) {
        System.out.println("--------------------");
        this.learnSpringService = learnSpringService;
    }


    @Value("${abc}")
    private String propp;

    @Resource
    private TwoService twoService;

    @Autowired
    private Environment environment;

    @Autowired
    private LearnSpringService learnSpringService;

    @Autowired
    private BeanFactory beanFactory;

    public void setLearnSpringService(LearnSpringService learnSpringService) {
        this.learnSpringService = learnSpringService;
    }

    public void setTwoService(TwoService twoService) {
        this.twoService = twoService;
    }

    public void setBeanFactory(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    @RequestMapping("/zsc.do")
    @ResponseBody
    public String getString(){
        return "zsc";
    }

    @RequestMapping("/")
    @ResponseBody
    public String getget(ServiceBO serviceBO, HttpServletRequest reque, HttpServletResponse response) throws IOException {

        System.out.println();
        learnSpringService.getName();

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("http://www.baidu.com");//直接将完整的表单html输出到页面
        response.getWriter().flush();
        response.getWriter().close();

        return "zsc";
    }

    @PostMapping("/zsczsc")
    @ResponseBody
    public String getzsczsc(@Valid  ServiceBO serviceBO){

        learnSpringService.getAge(serviceBO);
        return "zsc";
    }

    public void getString1(String name){
        System.out.println();
    }
    public int getString1(Integer i){
        return 1;
    }

    public static void main(String[] args) {
        ZscController zscController = new ZscController(null);
        System.out.println(zscController.getString1(1));
    }
}
